
from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response


# 重写JWT响应结果的方法
def jwt_response_payload_handler(token, user=None, request=None):
    return {
        'token': token,
        'username': user.username,
        'id': user.id
    }


# 自定义分页器设置
class CurPagination(PageNumberPagination):
    page_size = 10
    page_size_query_param = 'pagesize'
    max_page_size = page_size

    def get_paginated_response(self, data):
        # 重写返回数据格式
        return Response({
            'counts': self.page.paginator.count,
            'lists': data,
            'page': self.page.number,
            'pages': self.page.paginator.num_pages,
            'pagesize': self.page_size
            })
